package com.star.uc.infras.config.satoken;

import cn.dev33.satoken.jwt.StpLogicJwtForStateless;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.strategy.SaStrategy;
import cn.dev33.satoken.util.SaFoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 重写 Sa-Token 框架内部算法策略
 *
 * @author zhouhengzhe
 * @version 1.0
 * @date 2023/10/18 15:44
 */
@Configuration
public class SaTokenCustomConfig {
    /**
     * 重写 Sa-Token 框架内部算法策略
     */
    @Autowired
    public void rewriteSaStrategy() {
        /**
         *  重写 Token 生成策略
         */
        SaStrategy.instance.createToken = (loginId, loginType) -> {
            /**
             * 随机100位长度字符串
             */
            return SaFoxUtil.getRandomString(100);
        };
    }

    // Sa-Token 整合 jwt (Simple 简单模式)
    @Bean
    public StpLogic getStpLogicJwt() {
        return new StpLogicJwtForStateless();
    }
}
